<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="root">

    </div>
</body>
<script src="../react.js"></script>
<script src="../react-dom.js"></script>
<script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
<script type="text/babel">
    class App extends React.Component {
        state = {
            html: "<h1>好好学习天天向上</h1>",
            content: ""
        }
        render() {
            return (
                <div>
                    {
                        /* 
                         <div dangerouslySetInnerHTML={{
                            __html:this.state.html
                        }} ></div>
                        */
                        //dangerouslySetInnerHTML 用来渲染html标签
                    }

                    <div dangerouslySetInnerHTML={this.getHtml()} ></div>
                    <button onClick={() => this.getInfo()}>获取商品详情</button>
                    <div dangerouslySetInnerHTML={{
                        __html: this.state.content
                    }}></div>
                </div>
            )
        }
        getHtml() {
            return {
                __html: this.state.html
            }
        }
        getInfo() {
            let xhr = new XMLHttpRequest();
            xhr.open("get", "https://apif.java.crmeb.net/api/front/product/detail/2?type=normal");
            xhr.send();
            xhr.onreadystatechange = () => {
                if (xhr.readyState === 4) {
                    let res = JSON.parse(xhr.response);
                    console.log(res)
                    this.setState({
                        content: res.data.productInfo.content
                    })
                }
            }
        }
    }

    ReactDOM.render(<App />, document.getElementById("root"))
</script>

</html>